home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / progutil / stdwin.zoo / alfa / measure.c < prev    next >
C/C++ Source or Header  |  1989-10-18  |  721b  |  56 lines

  1. /* STANDARD WINDOWS -- TEXT MEASURING. */
  2.  
  3. #include "alfa.h"
  4.  
  5. int
  6. wlineheight()
  7. {
  8.     return 1;
  9. }
  10.  
  11. #define CHARWIDTH(c) ((c) < ' ' ? 2 : (c) < 0177 ? 1 : (c) < 0200 ? 2 : 4)
  12.  
  13. int
  14. wtextwidth(str, len)
  15.     char *str;
  16.     int len;
  17. {
  18.     int i;
  19.     int w= 0;
  20.     
  21.     if (len < 0)
  22.         len= (int)strlen(str);
  23.     for (i= 0; i < len; ++i) {
  24.         unsigned char c= str[i];
  25.         w += CHARWIDTH(c);
  26.     }
  27.     return w;
  28. }
  29.  
  30. int
  31. wcharwidth(c)
  32.     int c;
  33. {
  34.     c &= 0xff;
  35.     return CHARWIDTH(c);
  36. }
  37.  
  38. int
  39. wtextbreak(str, len, width)
  40.     char *str;
  41.     int len;
  42.     int width;
  43. {
  44.     int i;
  45.     
  46.     if (len < 0)
  47.         len= (int)strlen(str);
  48.     for (i= 0; i < len && width > 0; ++i) {
  49.         unsigned char c= str[i];
  50.         width -= CHARWIDTH(c);
  51.         if (width < 0)
  52.             break; /* Before incrementing i! */
  53.     }
  54.     return i;
  55. }
  56.